home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / stdlib / RCS / getenv.c,v < prev    next >
Encoding:
Text File  |  1989-03-22  |  2.4 KB  |  116 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     89.03.22.00.47.13;  author rab;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     88.05.21.16.17.51;  author ouster;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @@
  22.  
  23.  
  24. 1.2
  25. log
  26. @*** empty log message ***
  27. @
  28. text
  29. @/* 
  30.  * getenv.c --
  31.  *
  32.  *    Source code for the "getenv" library procedure.
  33.  *
  34.  * Copyright 1988 Regents of the University of California
  35.  * Permission to use, copy, modify, and distribute this
  36.  * software and its documentation for any purpose and without
  37.  * fee is hereby granted, provided that the above copyright
  38.  * notice appear in all copies.  The University of California
  39.  * makes no representations about the suitability of this
  40.  * software for any purpose.  It is provided "as is" without
  41.  * express or implied warranty.
  42.  */
  43.  
  44. #ifndef lint
  45. static char rcsid[] = "$Header: /sprite/src/lib/c/stdlib/RCS/getenv.c,v 1.1 88/05/21 16:17:51 ouster Exp Locker: rab $ SPRITE (Berkeley)";
  46. #endif /* not lint */
  47.  
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50.  
  51. extern char **environ;
  52.  
  53. /*
  54.  *----------------------------------------------------------------------
  55.  *
  56.  * getenv --
  57.  *
  58.  *    Locate an environment variable by a given name.
  59.  *
  60.  * Results:
  61.  *    The return value is a pointer to the value associated with
  62.  *    name, or 0 if there is no value registered for name.  The return
  63.  *    value points into environment storage, which is only guaranteed
  64.  *    to persist until the next call to setenv.
  65.  *
  66.  * Side effects
  67.  *    None.
  68.  *
  69.  *----------------------------------------------------------------------
  70.  */
  71.  
  72. char *
  73. getenv(name)
  74.     char    *name;        /* Name to retrieve value for. */
  75. {
  76.     char **envPtr;        /* pointer into list of environ. vars. */
  77.     register char *charPtr;    /* point into one environment variable */
  78.     register char *namePtr;    /* pointer into name */
  79.  
  80.     for (envPtr = environ; *envPtr != NULL; envPtr++) {
  81.     for (charPtr = *envPtr, namePtr = name; *charPtr == *namePtr;
  82.         charPtr++, namePtr++) {
  83.         if (*charPtr == '=') {
  84.         break;
  85.         }
  86.     }
  87.     if ((*charPtr == '=') && (*namePtr == NULL)) {
  88.         return charPtr+1;
  89.     }
  90.     }
  91.     return NULL;
  92. }
  93. @
  94.  
  95.  
  96. 1.1
  97. log
  98. @Initial revision
  99. @
  100. text
  101. @d17 2
  102. a18 2
  103. static char rcsid[] = "$Header: proto.c,v 1.2 88/03/11 08:39:08 ouster Exp $ SPRITE (Berkeley)";
  104. #endif not lint
  105. d20 3
  106. d52 1
  107. a52 1
  108.     for (envPtr = environ; *envPtr != 0; envPtr++) {
  109. d59 1
  110. a59 1
  111.     if ((*charPtr == '=') && (*namePtr == 0)) {
  112. d63 1
  113. a63 1
  114.     return 0;
  115. @
  116.